<?php

require_once(APPPATH.'controllers/crons/process_cron_info.php');

class Process_live_info extends Process_cron_info{

	function Process_live_info(){
		parent::Process_cron_info();
	}

	function index(){
		$this->load->model('m_channel');
		$this->run("SUITE_TICKET_LIVE",array("live"));
	}

	function process_response($response){
		try{
			$live_info = $response["resultset"];
			$channel = NULL;
			foreach($live_info as $row){
				if($row['action']=='del'){
					$this->m_channel->deleteById($row["signal_id"]);
				}else{
					$channel = $this->m_channel->getById($row["signal_id"]);
					if($channel==NULL)
					{//new -> se considera un canal ceibal
						$channel = new Channel();
						$channel->suite_id		= $row["signal_id"];
						$channel->id			= $row["xmltv_channel_id"];
						$channel->ceibal		= 1;
						$channel->name			= $row["xmltv_channel_id"];
						$channel->description	= 'Canal de Ceibal';
						$channel->active		= $row["broadcaster_streaming"];
						$channel->broadcasting	= $row["broadcaster_active"];
						$channel->last_update	= $date_now;
						$this->m_channel->create($channel);
					}
					else
					{//mod
						$channel->id			= $row["xmltv_channel_id"];
						$channel->active		= $row["broadcaster_streaming"];
						$channel->broadcasting	= $row["broadcaster_active"];
						$channel->last_update	= $date_now;
						$this->m_channel->update($channel);
					}
				}

			}

		}catch(Exception $ex){
			throw $ex;
		}
	}

}
?>
